﻿using DDD.Application.Services.CollectDeviceInfo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace DDD.Application.Services
{
    public class CollectAppleDeviceInfoService : ICollectDeviceInfo
    {
        private readonly HttpClient _httpClient;

        public CollectAppleDeviceInfoService(IHttpClientFactory httpClientFactory)
        {
            this._httpClient = httpClientFactory.CreateClient();
        }
        public string Provider { get; set; } = "Apple";

        public async Task<string> GetDeviceInfoAsync()
        {
            var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();

            var url = $"https://checkcoverage.apple.com/gc?t=image&timestamp={timestamp}";

            var dic = await _httpClient.GetFromJsonAsync<Dictionary<string, object>>(url);

            var imgBase64 = dic["binaryValue"];

            return "";
        }

        public Task<string> GetVerificationCodeAsync()  
        {
            throw new NotImplementedException();
        }
    }
}
